﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.admin
{
    public partial class WebForm12 : System.Web.UI.Page
    {
        private DataClasses1DataContext dc = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string id = Request.QueryString["id"];
                if (id == null)
                {
                    Response.Redirect("Policy.aspx");
                }
                else
                {
                    policy pol = this.dc.policies.Single(a => a.policyid.Equals(id));
                    this.txtpolicyname.Value = pol.policyname;
                    this.txtpolicydesc.Value = pol.policydesc;
                    this.txtamount.Value = string.Format("{0:0.##}", pol.amount);
                    this.txtemi.Value = string.Format("{0:0.##}", pol.emi);
                    this.DropDownList1.DataSource = this.dc.HospitalInfos.Where(c => c.hospitalid == pol.hospitalid);
                    this.DropDownList1.DataValueField = "hospitalid";
                    this.DropDownList1.DataTextField = "hospitalname";
                    this.DropDownList1.DataBind();
                    this.txtPolicyDuration.Value = pol.policyduration.ToString();
                }
            }
        }

        protected void ButtonUpdate_Click(object sender, EventArgs e)
        {
            string policyname = this.txtpolicyname.Value;
            string policydesc = this.txtpolicydesc.Value;
            decimal amount = Convert.ToDecimal(this.txtamount.Value);
            decimal emi = Convert.ToDecimal(this.txtemi.Value);
            string hospitalid = DropDownList1.SelectedValue.ToString();
            update(policyname, policydesc, amount, emi, hospitalid);

        }
        public void update(string policyname, string policydesc, decimal amount, decimal emi, string hospitalid)
        {
            string id = Request.QueryString["id"];
            policy pol = this.dc.policies.Single(p => p.policyid.Equals(id));
            pol.policyname = policyname;
            pol.policydesc = policydesc;
            pol.amount = amount;
            pol.emi = emi;
            pol.hospitalid = Convert.ToInt32(hospitalid);
            dc.SubmitChanges();
            this.Labelkq.Text = "Update Successful";
        }
    }
}